/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfopay.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfopay.entity.CampusinfoPay;
import com.lczyfz.campusinfo.modules.campusinfopay.service.CampusinfoPayService;

import java.util.List;

/**
 * 订单交易号Controller
 * @author zms
 * @version 2018-05-28
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfopay/campusinfoPay")
public class CampusinfoPayController extends BaseController {

	@Autowired
	private CampusinfoPayService campusinfoPayService;
	
	@ModelAttribute
	public CampusinfoPay get(@RequestParam(required=false) String id) {
		CampusinfoPay entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoPayService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoPay();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfopay:campusinfoPay:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoPay campusinfoPay, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoPay> page = campusinfoPayService.findPage(new Page<CampusinfoPay>(request, response), campusinfoPay);
		List<CampusinfoPay> campusinfoPays = campusinfoPayService.findList(campusinfoPay);
		model.addAttribute("campusinfoPays",campusinfoPays);
		model.addAttribute("page", page);
		return "modules/campusinfopay/campusinfoPayList";
	}

	@RequiresPermissions("campusinfopay:campusinfoPay:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoPay campusinfoPay, Model model) {
		model.addAttribute("campusinfoPay", campusinfoPay);
		return "modules/campusinfopay/campusinfoPayForm";
	}

	@RequiresPermissions("campusinfopay:campusinfoPay:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoPay campusinfoPay, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoPay)){
			return form(campusinfoPay, model);
		}
		campusinfoPayService.save(campusinfoPay);
		addMessage(redirectAttributes, "保存交易号成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfopay/campusinfoPay/?repage";
	}
	
	@RequiresPermissions("campusinfopay:campusinfoPay:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoPay campusinfoPay, RedirectAttributes redirectAttributes) {
		campusinfoPayService.delete(campusinfoPay);
		addMessage(redirectAttributes, "删除交易号成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfopay/campusinfoPay/?repage";
	}

}